package com.qiwo.common.controller;

import com.qiwo.common.utils.ImageUploadUtil;
import com.qiwo.common.utils.UploadProperties;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * Copyright
 *
 * @Author:chenwenchao
 * @Date:2018/10/7 0007
 * Description:
 */
@Controller
@RequestMapping("/upload/")
public class UploadController {
    private Logger logger = LoggerFactory.getLogger(UploadController.class.getName());
    @Resource
    private UploadProperties uploadProperties;
    @RequestMapping("ckUploadImg")
    public void ckUpdateImg(HttpServletRequest request, HttpServletResponse response){
        String DirectoryName = "upload/ck/";
        try{
            ImageUploadUtil.ckeditor(request, response, uploadProperties.getBasePath()+"/"+DirectoryName);

        }catch(Exception e){
            logger.error("CK上傳失敗：{}"+e.getMessage());
        }

    }

  /*  @RequestMapping("uploadImg")
    @ResponseBody
    public AbstractBean updateImg(HttpServletRequest request){
        String DirectoryName = "upload/other/";
        try{
            String fileName = ImageUploadUtil.upload(request, DirectoryName);
            return json(DirectoryName+fileName);
        }catch(Exception e){
            logger.error("上傳失敗：{}",e.getMessage());
            return fail(EnumSvrResult.ERROR_UPLOAD_IMG);
        }
    }*/
}
